<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>客服修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;margin:15px auto;overflow:auto;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label" >初始密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required  lay-verify="required" placeholder="初始密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" >新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newPassword" required lay-verify="required" placeholder="新密码" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" >再次输入新密码</label>
            <div class="layui-input-block">
                <input type="password" name="newPasswordAgain" required lay-verify="required" placeholder="再次输入新密码" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" >立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary" >重置</button>
            </div>
        </div>
    </form>
</div>
<div style="display:none;" id="upload"></div>
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>
<script>
    //Demo
    layui.use(['form' , 'jquery' , 'upload'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //监听提交
        form.on('submit(formDemo)', function(data){
            var data = data.field;
            if(data.password == undefined || data.password == "") {
                layer.msg("请输入初始密码") ;
                return false
            }
            if(data.newPassword == undefined || data.newPassword == "" || data.newPasswordAgain == undefined || data.newPasswordAgain == "") {
                layer.msg("新密码不能为空");
                return false
            }
            if(data.newPassword != data.newPasswordAgain) {
                layer.msg("两次新密码不一致");
                return false
            }
            data.token = sessionStorage.getItem("kefu_id");
            $.ajax({
                url:"/kefu/kefuChangePassword",
                data:data,
                success:function(res) {
                    if(res.code == 200) {
                        layer.msg("密码修改成功", {
                            icon: 1,
                            time: 1000
                        }, () => {
                            parent.location.href = "/index.html";
                        });
                    }else{
                        layer.msg(res.msg)
                    }
                }
            })
            return false;
        });
    });

    function upload(){
        $("#upload").click()
    }
</script>

</body>
</html>